package com.wxzz.elearing.user.api.app;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.ToolFormDto;
import com.wxzz.elearing.user.entity.ToolForm;
import com.wxzz.elearing.user.service.IToolFormService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2021-05-18
 */
@RestController
@RequestMapping("/wx-tool-form")
@Api(tags = "工具表单(小程序)")
public class WxToolFormController {

    @Autowired
    private IToolFormService iToolFormService;
    @Autowired
    private RedisTemplate<String,String> redisTemplate;
//    @ApiOperation(value = "添加一级表单(后台)", notes = "添加一级表单(后台)", httpMethod = "POST", tags = "后台")
//    @RequestMapping(value = "addToolForm", method = RequestMethod.POST)
//    public ReturnVO addToolForm(@RequestBody ToolForm toolForm, @RequestHeader String token) throws IOException {
//        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
//        toolForm.setEnterpriseId(jsonObject.getLong("enterpriseId"));
//        toolForm.setAdminUserId(jsonObject.getLong("id"));
//        return iToolFormService.addToolForm(toolForm);
//    }

    @ApiOperation(value = "一级工具表单列表(小程序)", notes = "一级工具表单列表(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "toolFormList", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<ToolForm>>> toolFormList(@RequestBody ToolFormDto toolFormDto, @RequestHeader String token) throws IOException {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        toolFormDto.setEnterpriseId(jsonObject.getLong("enterpriseId"));
        return iToolFormService.toolFormList(toolFormDto);
    }

//    @ApiOperation(value = "删除工具表单(后台)", notes = "删除工具表单(后台)", httpMethod = "POST", tags = "后台")
//    @RequestMapping(value = "deleteToolForm", method = RequestMethod.POST)
//    public ReturnVO deleteToolForm(@RequestHeader String token, @RequestBody ToolForm toolForm) {
////        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
////        adminWorkGuideline.setCreatePerson(jsonObject.getLong("enterpriseId"));
////        adminWorkGuideline.setCreatePerson(jsonObject.getString("nickname"));
//        return iToolFormService.deleteToolForm(toolForm);
//    }

}
